package client;

import java.io.BufferedReader;
import java.io.IOException;
import java.net.Socket;

public class ClientThreadAscoltaRisposta extends Thread{
	
	private Socket socket;
	BufferedReader bufferedReader;
	public boolean blocca=false;
	public String ultimoMess=null;
	public String ultimaRisp=null;
	public boolean rispOK=false;
	private Client client;
	
	public synchronized boolean isRispOK() {
		return rispOK;
	}

	public synchronized void setRispOK(boolean rispOK) {
		this.rispOK = rispOK;
	}

	public synchronized String getUltimaRisp() {
		return ultimaRisp;
	}

	public synchronized void setUltimaRisp(String ultimaRisp) {
		this.ultimaRisp = ultimaRisp;
	}

	public ClientThreadAscoltaRisposta(Socket socket,BufferedReader bufferedReader,Client client)throws IOException {
		this.socket=socket;
		this.client=client;
		this.bufferedReader=bufferedReader;
	}
	
	public void run(){
		
		while(true){
			try{
				ultimoMess=bufferedReader.readLine();
				System.out.println("leggo da ClientThreadAscoltaRisp: " + ultimoMess);
				if(ultimoMess.split("\\,")[0].equals("@cambioTurno")){
					client.cambioTurno(ultimoMess.split("\\,")[1]);
				}
				else{
					ultimaRisp=ultimoMess;
					setRispOK(true);
					synchronized(client.getServerInt()){
						client.getServerInt().notifyAll();
					}
				}
			}catch (IOException e){
				System.exit(0);
			}
						
		}
		
	}
	

}
